package com.sfac.springBoot.modules.test.dao;

import com.sfac.springBoot.modules.test.entity.Student;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description StudentDao
 * @Author HymanHu
 * @Date 2022/7/1 14:57
 */
@Repository
public interface StudentDao extends JpaRepository<Student, Integer> {
    Student getById(int id);
    List<Student> findAllByStudentName(String studentName);
    @Modifying
//    @Query(value = "update Student set studentName = :#{studentName} " +
//            "where id = :#{id}")
    @Query(nativeQuery = true, value = "update test_student set student_name = :#{#student.studentName} " +
			"where id = :#{#student.id}")
    void updateStudent(@Param("student") Student student);
}
